import json

import requests
from common.helper import get_request_url, get_request_headers


def new_workspace(name, prompt="Custom prompt for responses", query_refusal_response="Custom refusal message"):
    response = requests.post(
        url=get_request_url("v1/workspace/new"),
        headers=get_request_headers(),
        data={
          "name": f"{name}",
          "similarityThreshold": 0.7,
          "openAiTemp": 0.7,
          "openAiHistory": 20,
          "openAiPrompt": f"{prompt}",
          "queryRefusalResponse": f"{query_refusal_response}",
          "chatMode": "chat",
          "topN": 4
        }
    )
    if response.status_code == 200:
        return json.loads(response.text)
    else:
        print(f"request failed<{response.status_code}>: {response.text}")
        raise Exception("request failed")


if __name__ == "__main__":
    result = new_workspace("test")
    print(result)